﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using BenevolentSunData;

namespace BenevolentSun
{
    public class DimmerControl
    {

        Sprite sprite;

        Tween fader;

        public DimmerControl(ContentManager content)
        {
            sprite = new Sprite(content.Load<Texture2D>("Textures/White1x1"));
            sprite.Color = new Color(0, 0, 0, 0);
            sprite.Scale = new Vector2(1280, 720);
        }

        public void AdvanceToEnd()
        {
            if (fader != null)
            {
                fader.AdvanceToEnd();
                sprite.Color.A = (byte)fader.Value;
                fader = null;
            }
        }

        public void FadeIn()
        {
            fader = new Tween(sprite.Color.A, (byte)(255 * 0.8f), 0.25, Tween.LoopType.None);
        }

        public void FadeOut()
        {
            fader = new Tween(sprite.Color.A, 0, 0.25, Tween.LoopType.None);
        }

        public void Update(GameTime gameTime)
        {
            if (fader != null)
            {
                fader.Update(gameTime);
                sprite.Color.A = (byte)fader.Value;
                if (fader.IsFinished)
                    fader = null;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            sprite.Draw(spriteBatch);
        }

    }
}
